package com.example.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    private Long time11;
    private Date date;

    public DateUtils() {
        this.date = new Date();
        this.time11 =this.date.getTime();
    }


    /**
     * 获取时间戳
     * 输出结果:1438692801766
     */

    public void getTimeStamp() {
        Date date = new Date();
        long times = date.getTime();
        System.out.println(times);

        //第二种方法：
        new Date().getTime();
    }

    public String getTimeStampToString() {
        Date date = new Date();
        long times = date.getTime();
        return Long.toString(times);
    }

    //对当前对象的时间戳输出
    public String getTimeStampToString1(){
        long times = this.time11;
        return Long.toString(times);
    }
    /**
     * 获取格式化的时间
     * 输出格式：2015-08-04 20:55:35
     */

    public String getFormatDate(){
        Date date = new Date();
        long times = date.getTime();//时间戳
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(date);
        return dateString;
    }


    //对当下特定时间的格式转换
    public String getFmtDate(){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(this.date);
        return dateString;
    }

    public String getDate(){
        Date date = new Date();
        long times = date.getTime();//时间戳
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(date);
        return dateString;
    }


    /**
     * 将时间戳转化为标准时间
     * 输出：Tue Oct 07 12:04:36 CST 2014
     */

    public void timestampToDate(){
        long times = 1412654676572L;
        Date date = new Date(times);
        System.out.println(date);
    }
}
